package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.DishFlavor;
import com.example.dao.DishFlavorDao;
import com.example.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜品口味关系表(DishFlavor)表服务实现类
 *
 * @author makejava
 * @since 2022-05-24 16:11:53
 */
@Service("dishFlavorService")
public class DishFlavorServiceImpl extends ServiceImpl<DishFlavorDao,DishFlavor> implements DishFlavorService {
    @Autowired
    private DishFlavorDao dishFlavorDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public DishFlavor queryById(Long id) {
        return this.dishFlavorDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<DishFlavor> queryAllByLimit(int offset, int limit) {
        return this.dishFlavorDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param dishFlavor 实例对象
     * @return 实例对象
     */
    @Override
    public DishFlavor insert(DishFlavor dishFlavor) {
        this.dishFlavorDao.insert(dishFlavor);
        return dishFlavor;
    }

    /**
     * 修改数据
     *
     * @param dishFlavor 实例对象
     * @return 实例对象
     */
    @Override
    public DishFlavor update(DishFlavor dishFlavor) {
        this.dishFlavorDao.update(dishFlavor);
        return this.queryById(dishFlavor.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.dishFlavorDao.deleteById(id) > 0;
    }
}